package com.wuyou.designPatterns.command;

import java.awt.*;

/**
 * DrawCanvas
 *
 * @Date 2024/10/18 16:04
 * @Author 无忧
 */
public class DrawCanvas extends Canvas implements Drawable {

    // 颜色
    private Color color = Color.red;
    // 要绘制的圆点的半径
    private int radius = 6;
    // 命令的历史记录
    private MacroCommand history;

    public DrawCanvas(int width, int height, MacroCommand history){
        setSize(width, height);
        setBackground(Color.white);
        this.history = history;
    }

    /**
     * 重新全部绘制
     * @param x
     * @param y
     */
    public void paint(int x, int y) {
        history.execute();
    }

    /**
     * 绘制
     * @param x
     * @param y
     */
    @Override
    public void draw(int x, int y){
        Graphics graphics = getGraphics();
        graphics.setColor(color);
        graphics.fillOval(x - radius, y - radius, radius * 2, radius * 2);
    }
}
